import { getAdminLoginApi } from "@/api/admin"
import { App, Button } from "antd"
import { useNavigate } from "react-router";

const LoginPage = () => {

  const { message } = App.useApp();
  const navigate = useNavigate();
  const getAdminLogin = (data: object) => {
    getAdminLoginApi(data).then(res => {
      if (res.code == 200) {
        message.success('登录成功');
        localStorage.loginToken = res.token;
        navigate('/home', { replace: true })
      } else {
        message.error(res.message)
      }
    })
  }

  return (
    <>
      <div>登录页</div>
      <>
        <Button type="primary" onClick={() => {
          getAdminLogin({ account: 'zhangsan', password: '123' })
        }}>超管登录</Button>
      </>
      <Button type="primary" onClick={() => {
        getAdminLogin({ account: 'lisi', password: '123' })
      }}
      >普管登录</Button>
      <Button type="primary" onClick={() => {
        getAdminLogin({ account: 'wangwu', password: '123' })
      }}
      >按钮登录</Button>
    </>
  )
}

export default LoginPage